package yana.tpe.onlineshop.services.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import yana.tpe.onlineshop.domain.dao.CommentDao;
import yana.tpe.onlineshop.domain.domains.Comment;
import yana.tpe.onlineshop.domain.domains.Product;
import yana.tpe.onlineshop.services.CommentService;
import yana.tpe.onlineshop.services.ProductService;

/**
 *
 */
//@Service
@Transactional
public class CommentServiceImpl extends AbstractServiceImpl<Integer, Comment>
        implements CommentService {

    private static final Logger logger = LoggerFactory.getLogger(CommentServiceImpl.class);
    
    @Autowired
    private CommentDao commentDao;
    
    @Autowired
    private ProductService productService;

    @Override
    protected CommentDao getDao() {
        return commentDao;
    }

    @Override
    @Transactional
    public void addComment(Integer productId, Comment comment) {
        logger.debug("Try to add comment [{}], to product [id={}]", comment, productId);
        
        Product product = productService.get(productId);
        
        logger.debug("Product is [{}]", product);
        
        comment.setProduct(product);
        save(comment);
    }
}
